package com.wwdx.controller.admin;

import com.wwdx.controller.base.BaseController;
import com.wwdx.model.WwdxXiaodModel;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * @author liguoliang
 * @date 2017/12/8
 */
@Controller
@RequestMapping("/system/wwdx_xiaod")
public class WwdxXiaodController extends BaseController{

    /**
     * 列表
     */
    @RequestMapping("/list")
    public ModelAndView list(@RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "rows",defaultValue = "10") Integer rows) {

        ModelAndView mav = new ModelAndView();
        mav.addObject("listSize", wwdxXiaodService.selectModelCount());
        mav.addObject("list", wwdxXiaodService.selectModelList(page, rows));
        return mav;
    }

    /**
     * 新增
     */
    @RequestMapping("/create")
    public ModelAndView create(Long userid,Integer typel) {
        ModelAndView mav = new ModelAndView();
        mav.addObject("list",wwdxXiaodService.selectModelList(userid));
        mav.addObject("personalmodel",wwdxPersonalService.getById(userid));
        mav.addObject("userid",userid);
        mav.addObject("typel",typel);
        return mav;
    }

    /**
     * 新增保存
     */
    @RequestMapping("/save")
    public String save(WwdxXiaodModel model, Integer typel){
        wwdxXiaodService.modifyMessageByUserId(model.getUserid());
        model.setGmt_created(new Date());
        model.setGmt_modified(new Date());
        model.setType(0);
        model.setStatus(0);
        wwdxXiaodService.save(model);
        String url;
        if(typel==0){
             url="redirect:/system/wwdx_xiaod/list";
        }else {
            url="redirect:/system/user/list";
        }
        return url;
    }
}